﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;

namespace NExplorer.Controls
{
	internal class ExplorerContextMenu : ContextMenuStrip
	{
		public ExplorerMenuItem AddCommand(ICommand command)
		{
			ExplorerMenuItem menuItem = new ExplorerMenuItem(command);
			Items.Add(menuItem);

			return menuItem;
		}

		public IList<ExplorerMenuItem> AddCommands(ICollection<ICommand> commands)
		{
			List<ExplorerMenuItem> menuItems = new List<ExplorerMenuItem>();
			
			foreach (ICommand command in commands)
			{
				menuItems.Add(AddCommand(command));
			}

			return menuItems;
		}

		public void AddSeparator()
		{
			Items.Add(new ToolStripSeparator());
		}

        protected override void OnClosed(ToolStripDropDownClosedEventArgs e)
        {
            base.OnClosed(e);

            foreach (IDisposable menuItem in new ArrayList(Items))
            {
                menuItem.Dispose();
            }
        }
	}
}
